package com.android.demo.widget.takeacay;

import org.json.JSONException;
import org.json.JSONObject;

public class ProductInfo {
//	"id": "1",
//	"name": "name test",
//	"description": "description test",
//	"zip": "",
//	"address": "",
//	"image": "1301574663.bmp",
//	"create_time": "1301574663",
//	"update_time": "0"
	public long id = 0 ;
	public long tick = 0 ;
	public String name = "";
	public String phone = "";
	public String des  = "";
	public String address  = "";
	public String imageUrl  = "";
	public String bussinessHours  = "";
	public long createTime = 0;
	public long updateTime = 0;
	public int collect = 0;
	
	// 纬度
	public double latitude;
	// 经度
	public double longitude;
	
	public ProductInfo(){}
	public ProductInfo(double lati, double longti, String iname, String iphone, String ides){
		this.name = iname;
		this.phone = iphone;
		this.des = ides;
		this.latitude = lati;
		this.longitude = longti;
	}
	public ProductInfo(ProductInfo info) {
		this.id = info.id;
		this.name = info.name;
		this.phone = info.phone;
		this.des = info.des;
		this.address = info.address;
		this.imageUrl = info.imageUrl;
		this.bussinessHours = info.bussinessHours;
		this.createTime = info.createTime;
		this.updateTime = info.updateTime;
		this.latitude = info.latitude;
		this.longitude = info.longitude;
		this.tick = info.tick;
		this.collect = info.collect;
	}
	
	public ProductInfo(JSONObject json) throws JSONException{
		id = json.getLong("id");
		
		name = json.getString("name");
		des = json.getString("description");
		latitude = json.getDouble("latitude");
		longitude = json.getDouble("longitude");
		address = json.getString("address");
		imageUrl = json.getString("image");
		
		createTime = json.getLong("create_time");
		updateTime = json.getLong("update_time");
		if (json.has("tick")) {
			tick = json.getLong("tick");
		}
		
		JSONObject telephone = json.getJSONObject("telephones");
		phone = telephone.getString("number");
	}
//	public String getOriginUrl(){
//		if (imageUrl==null || imageUrl.length()==0) return "";
//		return getImageUrl(imageUrl);
//	}
	public String getThumbUrl(){
		if (imageUrl==null || imageUrl.length()==0) return "";
		return getImageThumbUrl(imageUrl);
	}
	public static String getImageUrl(String imageName){
		return DevConfig.BASE_URL+"/images/" + imageName;	
	}
	public static String getImageThumbUrl(String imageName){
		return DevConfig.BASE_URL+"/images/" + "thumb_"+imageName;	
	}
	
	public static String getPhoneFormat(String number){
		if (number.length()==0) return "";
		String pre = "<font color=\"#DB0000\">";
		String end = "</font>";
		String pre1 = "<font color=\"#111111\">";
		String end1 = "</font>";
		return pre+"电话:"+end+" "+pre1+number+end1;
	}
}
